package com.test.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.CancellableFormController;

import com.test.model.UserModel;

public class CanCancelRegisterSimpleFormController extends CancellableFormController {

	public CanCancelRegisterSimpleFormController() {
		setCommandClass(UserModel.class); // 设置命令对象实现类
		setCommandName("user");// 设置命令对象的名字
		System.out.println("...CanCancelRegisterSimpleFormController...");
	}

	// form object 表单对象，提供展示表单时的表单数据（使用commandName放入请求）
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		UserModel user = new UserModel();
		user.setUsername("请输入用户名");
		System.out.println("...formBackingObject...");
		return user;
	}

	// 提供展示表单时需要的一些其他数据
	protected Map<String, Object> referenceData(HttpServletRequest request)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("cityList", Arrays.asList("山东", "北京", "上海"));
		System.out.println("...referenceData...");
		return map;
	}

	protected void doSubmitAction(Object command) throws Exception {
		UserModel user = (UserModel) command;
		// TODO 调用业务对象处理
		System.out.println(user);
		System.out.println("...doSubmitAction...");
	}

	
	@Override
	protected ModelAndView onCancel(Object command) throws Exception {
		UserModel user = (UserModel) command;
		// TODO 调用业务对象处理
		System.out.println(user);
		System.out.println("...onCancel...");
		return super.onCancel(command);
	}

}
